<#include "./template/general_temp.ftl">

<#macro content>
<div class="row" xmlns:input="http://www.w3.org/1999/html" xmlns:input="http://www.w3.org/1999/html">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-edit"></i>编辑</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content">
                <#if !no_obj??>
                    <@form.form modelAttribute="editDictCommand" role="form" enctype="multipart/form-data">
                        <@form.errors path='*' element="div" cssClass="alert alert-success" cssErrorClass="alert alert-danger"/>
                        <#if no_error??>
                            <div class="alert alert-success">
                                <strong>Well done! </strong>提交成功。
                            </div>
                        </#if>
                        <div class="form-group" id="imgBlock">
                            <@form.hidden path="imgUrl" id="iconUrlImg"/>
                            <#if editDictCommand.imgUrl?? && editDictCommand.imgUrl != "">
                                <img style='width:200px;' src='${base}/system/getImg?imgId=${editDictCommand.imgUrl}'/>
                            </#if>
                        </div>
                        <div class="form-group">
                            <label for="imgSel">选择图片</label>
                            <input data-no-uniform="true" type="file" id="imgSel" class="file_upload">
                        </div>
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">标题</label>
                            <@form.input path="title" cssClass="form-control" id="title"/>
                        </div>
                        <div class="form-group">
                            <label for="content">内容</label>
                            <@form.textarea path="content" id="dict_content"></@form.textarea>
                        </div>
                        <div class="form-group">
                            <label for="source">来源</label>
                            <@form.input path="source" cssClass="form-control" id="source"/>
                        </div>
                        <div class="form-group">
                            <label for="cat">分类</label>
                            <@form.select path="cat">
                                <#list cats as cat>
                                    <@form.option value="${cat.id}" label="${cat.name}" />
                                </#list>
                            </@form.select>
                        </div>
                        <div class="form-group">
                            <label for="status">状态</label>
                            <@form.radiobutton path="status" value="1"/>显示
                            <@form.radiobutton path="status" value="0"/>隐藏
                        </div>
                        <button type="submit" class="btn btn-default">提交</button>
                    </@form.form>
                <#else>
                    <div class="alert alert-danger">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>Oh snap!</strong>没有找到数据！
                    </div>
                </#if>
            </div>
        </div>
    </div>
    <!--/span-->
</div>
<!--/row-->
</#macro>

<#macro script>
<script type="text/javascript">
    var ue = UE.getEditor('dict_content');

    //uploadify - multiple uploads
    $('#imgSel').uploadify({
        'swf': '${base}/system/charisma-static/misc/uploadify.swf',
        'uploader': '${base}/system/uploadImg',
        'fileTypeExts': '*.jpg;*.gif;*.jpeg;*.png;',
        'buttonText' : '请选择图片',
        'fileObjName':'file',
        'multi': false,
        onSelect : function(file) {//当每个文件添加至队列后触发
            if(file.size >= 2 * 1024 * 1024){
                alert("选择文件不能超过2MB");
                return false;
            }
        },
        onError: function(event, queueID, fileObj) {
            alert("文件:" + fileObj.name + "上传失败");
        },
        onUploadSuccess: function(file,data,response){
            data = JSON.parse(data);
            $("#imgBlock img").remove();
            $("#imgBlock").append("<img style='width:200px;' src='${base}/system/getImg?imgId=" + data.filePath + "'/>");
            $("#iconUrlImg").val(data.filePath);
        }
    });
</script>
</#macro>
